/*   1:    */ package org.intellij.images.ui;
/*   2:    */ 
/*   3:    */

import com.intellij.openapi.ui.Messages;
import com.intellij.ui.JBColor;
import com.intellij.util.ui.UIUtil;
import icons.ImagesIcons;
import org.intellij.images.ImagesBundle;
import org.intellij.images.editor.ImageDocument;
import org.jetbrains.annotations.NonNls;

import javax.swing.*;
import javax.swing.plaf.ComponentUI;
import java.awt.*;
import java.awt.image.BufferedImage;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */
/*  18:    */
/*  19:    */
/*  20:    */
/*  21:    */
/*  22:    */ 
/*  23:    */ public class ThumbnailComponentUI
/*  24:    */   extends ComponentUI
/*  25:    */ {
/*  26:    */   @NonNls
/*  27:    */   private static final String a = "...";
/*  28:    */   @NonNls
/*  29:    */   private static final String b = "ThumbnailComponent.errorString";
/*  30: 45 */   private static final Color c = new Color(142, 168, 206);
/*  31: 46 */   private static final Color d = new Color(128, 0, 128);
/*  32: 47 */   private static final Color e = new Color(0, 128, 0);
/*  33: 48 */   private static final Color f = new Color(128, 128, 0);
/*  34: 49 */   private static final Color g = new Color(0, 0, 128);
/*  35: 51 */   private static final ThumbnailComponentUI h = new ThumbnailComponentUI();
/*  36:    */   
/*  37:    */   static
/*  38:    */   {
/*  39: 54 */     UIManager.getDefaults().put("ThumbnailComponent.errorString", ImagesBundle.message("thumbnails.component.error.text", new Object[0]));
/*  40:    */   }
/*  41:    */   
/*  42:    */   public void paint(Graphics paramGraphics, JComponent paramJComponent)
/*  43:    */   {
/*  44: 60 */     ThumbnailComponent localThumbnailComponent = (ThumbnailComponent)paramJComponent;
/*  45: 61 */     if (localThumbnailComponent != null)
/*  46:    */     {
/*  47: 62 */       c(paramGraphics, localThumbnailComponent);
/*  48: 64 */       if (localThumbnailComponent.isDirectory()) {
/*  49: 65 */         a(paramGraphics, localThumbnailComponent);
/*  50:    */       } else {
/*  51: 67 */         b(paramGraphics, localThumbnailComponent);
/*  52:    */       }
/*  53: 71 */       e(paramGraphics, localThumbnailComponent);
/*  54:    */     }
/*  55:    */   }
/*  56:    */   
/*  57:    */   private void a(Graphics paramGraphics, ThumbnailComponent paramThumbnailComponent)
/*  58:    */   {
/*  59: 77 */     ImagesIcons.ThumbnailDirectory.paintIcon(paramThumbnailComponent, paramGraphics, 5, 5);
/*  60:    */     
/*  61: 79 */     int i = paramThumbnailComponent.getImagesCount();
/*  62: 80 */     if (i > 0)
/*  63:    */     {
/*  64: 81 */       String str = ImagesBundle.message("icons.count", new Object[] { Integer.valueOf(i) });
/*  65:    */       
/*  66: 83 */       Font localFont = b();
/*  67: 84 */       FontMetrics localFontMetrics = paramGraphics.getFontMetrics(localFont);
/*  68: 85 */       paramGraphics.setColor(Color.BLACK);
/*  69: 86 */       paramGraphics.setFont(localFont);
/*  70: 87 */       paramGraphics.drawString(str, 5 + (ImagesIcons.ThumbnailDirectory.getIconWidth() - localFontMetrics.stringWidth(str)) / 2, ImagesIcons.ThumbnailDirectory.getIconHeight() / 2 + localFontMetrics.getAscent());
/*  71:    */     }
/*  72:    */   }
/*  73:    */   
/*  74:    */   private void b(Graphics paramGraphics, ThumbnailComponent paramThumbnailComponent)
/*  75:    */   {
/*  76: 94 */     ImagesIcons.ThumbnailBlank.paintIcon(paramThumbnailComponent, paramGraphics, 5, 5);
/*  77:    */     
/*  78: 96 */     ImageComponent localImageComponent = paramThumbnailComponent.getImageComponent();
/*  79: 97 */     ImageDocument localImageDocument = localImageComponent.getDocument();
/*  80: 98 */     BufferedImage localBufferedImage = localImageDocument.getValue();
/*  81: 99 */     if (localBufferedImage != null) {
/*  82:100 */       d(paramGraphics, paramThumbnailComponent);
/*  83:    */     } else {
/*  84:102 */       g(paramGraphics, paramThumbnailComponent);
/*  85:    */     }
/*  86:105 */     f(paramGraphics, paramThumbnailComponent);
/*  87:    */   }
/*  88:    */   
/*  89:    */   private void c(Graphics paramGraphics, ThumbnailComponent paramThumbnailComponent)
/*  90:    */   {
/*  91:109 */     Dimension localDimension = paramThumbnailComponent.getSize();
/*  92:110 */     paramGraphics.setColor(paramThumbnailComponent.getBackground());
/*  93:111 */     paramGraphics.fillRect(0, 0, localDimension.width, localDimension.height);
/*  94:    */   }
/*  95:    */   
/*  96:    */   private void d(Graphics paramGraphics, ThumbnailComponent paramThumbnailComponent)
/*  97:    */   {
/*  98:115 */     ImageComponent localImageComponent = paramThumbnailComponent.getImageComponent();
/*  99:116 */     BufferedImage localBufferedImage = localImageComponent.getDocument().getValue();
/* 100:    */     
/* 101:118 */     int i = ImagesIcons.ThumbnailBlank.getIconHeight();
/* 102:    */     
/* 103:    */ 
/* 104:121 */     i -= a(paramGraphics, localBufferedImage);
/* 105:    */     
/* 106:123 */     i -= a(paramThumbnailComponent, paramGraphics);
/* 107:    */     
/* 108:    */ 
/* 109:126 */     a(paramGraphics, localImageComponent, i);
/* 110:    */   }
/* 111:    */   
/* 112:    */   private int a(Graphics paramGraphics, BufferedImage paramBufferedImage)
/* 113:    */   {
/* 114:130 */     String str = ImagesBundle.message("icon.dimensions", new Object[] { Integer.valueOf(paramBufferedImage.getWidth()), Integer.valueOf(paramBufferedImage.getHeight()), Integer.valueOf(paramBufferedImage.getColorModel().getPixelSize()) });
/* 115:    */     
/* 116:132 */     Font localFont = b();
/* 117:133 */     FontMetrics localFontMetrics = paramGraphics.getFontMetrics(localFont);
/* 118:134 */     paramGraphics.setColor(Color.BLACK);
/* 119:135 */     paramGraphics.setFont(localFont);
/* 120:136 */     paramGraphics.drawString(str, 8, 7 + localFontMetrics.getAscent());
/* 121:    */     
/* 122:138 */     return localFontMetrics.getHeight();
/* 123:    */   }
/* 124:    */   
/* 125:    */   private int a(ThumbnailComponent paramThumbnailComponent, Graphics paramGraphics)
/* 126:    */   {
/* 127:142 */     Font localFont = b().deriveFont(1);
/* 128:143 */     FontMetrics localFontMetrics = paramGraphics.getFontMetrics(localFont);
/* 129:    */     
/* 130:145 */     String str = paramThumbnailComponent.getFormat().toUpperCase();
/* 131:146 */     int i = localFontMetrics.stringWidth(str);
/* 132:147 */     int j = ImagesIcons.ThumbnailBlank.getIconWidth() - i + 2;
/* 133:148 */     int k = ImagesIcons.ThumbnailBlank.getIconHeight() - localFontMetrics.getHeight() + 4;
/* 134:149 */     paramGraphics.setColor(c);
/* 135:150 */     paramGraphics.drawLine(j - 3, k - 1, j + i + 1, k - 1);
/* 136:151 */     paramGraphics.drawLine(j - 4, k, j - 4, k + localFontMetrics.getHeight() - 1);
/* 137:152 */     paramGraphics.setColor(a(str));
/* 138:153 */     paramGraphics.setFont(localFont);
/* 139:154 */     paramGraphics.drawString(str, j, k + localFontMetrics.getAscent());
/* 140:    */     
/* 141:    */ 
/* 142:    */ 
/* 143:    */ 
/* 144:    */ 
/* 145:160 */     return localFontMetrics.getHeight();
/* 146:    */   }
/* 147:    */   
/* 148:    */   private Color a(String paramString)
/* 149:    */   {
/* 150:164 */     if ("PNG".equals(paramString)) {
/* 151:165 */       return d;
/* 152:    */     }
/* 153:166 */     if ("GIF".equals(paramString)) {
/* 154:167 */       return e;
/* 155:    */     }
/* 156:168 */     if (("JPG".equals(paramString)) || ("JPEG".equals(paramString))) {
/* 157:169 */       return f;
/* 158:    */     }
/* 159:170 */     if (("BMP".equals(paramString)) || ("WBMP".equals(paramString))) {
/* 160:171 */       return g;
/* 161:    */     }
/* 162:173 */     return Color.BLACK;
/* 163:    */   }
/* 164:    */   
/* 165:    */   private void a(Graphics paramGraphics, ImageComponent paramImageComponent, int paramInt)
/* 166:    */   {
/* 167:179 */     int i = ImagesIcons.ThumbnailBlank.getIconWidth() - 10;
/* 168:180 */     int j = paramInt - 10;
/* 169:    */     
/* 170:182 */     BufferedImage localBufferedImage = paramImageComponent.getDocument().getValue();
/* 171:183 */     int k = localBufferedImage.getWidth();
/* 172:184 */     int m = localBufferedImage.getHeight();
/* 173:186 */     if ((k > i) || (m > j))
/* 174:    */     {
/* 175:    */       double d1;
/* 176:187 */       if (k > i)
/* 177:    */       {
/* 178:188 */         d1 = i / k;
/* 179:189 */         k = i;
/* 180:190 */         m = (int)(m * d1);
/* 181:    */       }
/* 182:192 */       if (m > j)
/* 183:    */       {
/* 184:193 */         d1 = j / m;
/* 185:194 */         m = j;
/* 186:195 */         k = (int)(k * d1);
/* 187:    */       }
/* 188:    */     }
/* 189:199 */     paramImageComponent.setCanvasSize(k, m);
/* 190:200 */     Dimension localDimension = paramImageComponent.getSize();
/* 191:    */     
/* 192:202 */     int n = 5 + (ImagesIcons.ThumbnailBlank.getIconWidth() - localDimension.width) / 2;
/* 193:203 */     int i1 = 5 + (ImagesIcons.ThumbnailBlank.getIconHeight() - localDimension.height) / 2;
/* 194:    */     
/* 195:    */ 
/* 196:206 */     paramImageComponent.paint(paramGraphics.create(n, i1, localDimension.width, localDimension.height));
/* 197:    */   }
/* 198:    */   
/* 199:    */   private void e(Graphics paramGraphics, ThumbnailComponent paramThumbnailComponent)
/* 200:    */   {
/* 201:210 */     Font localFont = UIUtil.getLabelFont();
/* 202:211 */     FontMetrics localFontMetrics = paramGraphics.getFontMetrics(localFont);
/* 203:    */     
/* 204:213 */     paramGraphics.setFont(localFont);
/* 205:214 */     paramGraphics.setColor(paramThumbnailComponent.getForeground());
/* 206:    */     
/* 207:216 */     String str1 = paramThumbnailComponent.getFileName();
/* 208:217 */     String str2 = str1;
/* 209:218 */     while (localFontMetrics.stringWidth(str2) > ImagesIcons.ThumbnailBlank.getIconWidth() - 8) {
/* 210:219 */       str2 = str2.substring(0, str2.length() - 1);
/* 211:    */     }
/* 212:222 */     if (str1.equals(str2))
/* 213:    */     {
/* 214:224 */       paramGraphics.drawString(str1, 6 + (ImagesIcons.ThumbnailBlank.getIconWidth() - 2 - localFontMetrics.stringWidth(str2)) / 2, ImagesIcons.ThumbnailBlank.getIconHeight() + 8 + localFontMetrics.getAscent());
/* 215:    */     }
/* 216:    */     else
/* 217:    */     {
/* 218:227 */       int i = localFontMetrics.stringWidth("...");
/* 219:228 */       while (localFontMetrics.stringWidth(str2) > ImagesIcons.ThumbnailBlank.getIconWidth() - 8 - i) {
/* 220:229 */         str2 = str2.substring(0, str2.length() - 1);
/* 221:    */       }
/* 222:231 */       paramGraphics.drawString(str2 + "...", 6, ImagesIcons.ThumbnailBlank.getIconHeight() + 8 + localFontMetrics.getAscent());
/* 223:    */     }
/* 224:    */   }
/* 225:    */   
/* 226:    */   private void f(Graphics paramGraphics, ThumbnailComponent paramThumbnailComponent)
/* 227:    */   {
/* 228:236 */     Font localFont = b();
/* 229:237 */     FontMetrics localFontMetrics = paramGraphics.getFontMetrics(localFont);
/* 230:238 */     paramGraphics.setColor(Color.BLACK);
/* 231:239 */     paramGraphics.setFont(localFont);
/* 232:240 */     paramGraphics.drawString(paramThumbnailComponent.getFileSizeText(), 8, ImagesIcons.ThumbnailBlank.getIconHeight() + 4 - localFontMetrics.getHeight() + localFontMetrics.getAscent());
/* 233:    */   }
/* 234:    */   
/* 235:    */   private void g(Graphics paramGraphics, ThumbnailComponent paramThumbnailComponent)
/* 236:    */   {
/* 237:248 */     Font localFont = b();
/* 238:249 */     FontMetrics localFontMetrics = paramGraphics.getFontMetrics(localFont);
/* 239:    */     
/* 240:251 */     Messages.getErrorIcon().paintIcon(paramThumbnailComponent, paramGraphics, 5 + (ImagesIcons.ThumbnailBlank.getIconWidth() - Messages.getErrorIcon().getIconWidth()) / 2, 5 + (ImagesIcons.ThumbnailBlank.getIconHeight() - Messages.getErrorIcon().getIconHeight()) / 2);
/* 241:    */     
/* 242:    */ 
/* 243:    */ 
/* 244:    */ 
/* 245:    */ 
/* 246:    */ 
/* 247:    */ 
/* 248:259 */     String str = a();
/* 249:260 */     paramGraphics.setColor(JBColor.RED);
/* 250:261 */     paramGraphics.setFont(localFont);
/* 251:262 */     paramGraphics.drawString(str, 8, 8 + localFontMetrics.getAscent());
/* 252:    */   }
/* 253:    */   
/* 254:    */   private String a()
/* 255:    */   {
/* 256:266 */     return UIManager.getString("ThumbnailComponent.errorString");
/* 257:    */   }
/* 258:    */   
/* 259:    */   private static Font b()
/* 260:    */   {
/* 261:270 */     Font localFont = UIUtil.getLabelFont();
/* 262:271 */     return localFont.deriveFont(localFont.getSize2D() - 2.0F);
/* 263:    */   }
/* 264:    */   
/* 265:    */   public Dimension getPreferredSize(JComponent paramJComponent)
/* 266:    */   {
/* 267:275 */     Font localFont = UIUtil.getLabelFont();
/* 268:276 */     FontMetrics localFontMetrics = paramJComponent.getFontMetrics(localFont);
/* 269:277 */     return new Dimension(ImagesIcons.ThumbnailBlank.getIconWidth() + 10, ImagesIcons.ThumbnailBlank.getIconHeight() + localFontMetrics.getHeight() + 15);
/* 270:    */   }
/* 271:    */   
/* 272:    */   public static ComponentUI createUI(JComponent paramJComponent)
/* 273:    */   {
/* 274:285 */     return h;
/* 275:    */   }
/* 276:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.intellij.images.ui.ThumbnailComponentUI

 * JD-Core Version:    0.7.0.1

 */